﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RTGS.Library.Report;
using System.Configuration;
using System.Data;
using Microsoft.Reporting.WebForms;
using RTGS.Library.DataAccess.Rtgs;
using RTGS.Library.Entities.Rtgs;
using RTGS.Library.DataAccess.UserManagement;
using RTGS.Library.Entities.UserManagement;

namespace RTGS.Web.page.report
{
    public partial class report_reportSptDetailRecordO : BasePage
    {
        ReportSptDetailRecordO reportDal = new ReportSptDetailRecordO(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        private stpRecordDetailORepo stpRecordDetailORepo = new stpRecordDetailORepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);

        private sysTLogRepo logDal = new sysTLogRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        private sysTLog log = new sysTLog();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ////STATUS
                //List<stpRecordDetailO> listTrn = stpRecordDetailORepo.GetList();
                //var Status = from status in listTrn
                //             orderby status.recordDetailOrecordStatus
                //             group status by status.recordDetailOrecordStatus into gstatus
                //             select new { statusRecord = gstatus.Key, Accounts = gstatus }
                //               ;

                //// Output the email address and the count of records for each group
                //foreach (var itemstatus in Status)
                //{
                //    ddlStatus.Items.Add(new ListItem(itemstatus.statusRecord, itemstatus.statusRecord));
                //}

                //ddlStatus.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

                try
                {
                    if (Context.Request.Params["status"] != null)
                    {
                        string parameters = string.Empty;
                        string status = Context.Request.Params["status"].ToString();
                        if (status.Trim().Length > 1)
                        {
                            parameters = " WHERE [RECORD_DETAIL_ORECORD_Status] ='" + status + "'";

                            DataTable dt = reportDal.GetReportSptDetailRecordO(parameters);

                            rsViewer.Reset();
                            if (status.Trim().ToUpper() == "DO")
                                rsViewer.LocalReport.ReportPath = Server.MapPath("~/reportviewer/rptSptDetailRecordO_Drop.rdlc");
                            if (status.Trim().ToUpper() == "OK")
                                rsViewer.LocalReport.ReportPath = Server.MapPath("~/reportviewer/rptSptDetailRecordO_Ok.rdlc");

                            ReportDataSource rds = new ReportDataSource();
                            rds.Name = "DataSet1";
                            rds.Value = dt;

                            rsViewer.LocalReport.DataSources.Clear();
                            rsViewer.LocalReport.DataSources.Add(rds);
                            rsViewer.LocalReport.Refresh();

                            log = new sysTLog();
                            log.logEvent = "View Report SPT_DETAIL_RECORD_O Success";
                            log.logMessage = string.Empty;

                        }
                    }

                   

                }
                catch (Exception ex)
                {
                    log = new sysTLog();
                    log.logEvent = "View Report SPT_DETAIL_RECORD_O Error";
                    log.logMessage = ex.Message;

                    Response.Write(ex.Message);
                }
                finally
                {
                    log.logSource = "reportSptDetailRecordO.aspx";
                    log.createdBy = base.UserLoggedIn;
                    log.createdDate = DateTime.Now;
                    logDal.Save(log);
                }

            }
        }


        protected void btnDisplay_Click(object sender, EventArgs e)
        {

            //try
            //{
            //    string parameters = string.Empty;
            //    string status = ddlStatus.SelectedValue.Trim();
            //    if (status.Trim().Length > 1)
            //    {
            //        parameters = " WHERE [RECORD_DETAIL_ORECORD_Status] ='" + status + "'";

            //        DataTable dt = reportDal.GetReportSptDetailRecordO(parameters);

            //        rsViewer.Reset();
            //        if (status.Trim().ToUpper() == "DO")
            //            rsViewer.LocalReport.ReportPath = Server.MapPath("~/reportviewer/rptSptDetailRecordO.rdlc");
            //         if (status.Trim().ToUpper() == "OK")
            //             rsViewer.LocalReport.ReportPath = Server.MapPath("~/reportviewer/rptSptDetailRecordO_Ok.rdlc");

            //        ReportDataSource rds = new ReportDataSource();
            //        rds.Name = "DataSet1";
            //        rds.Value = dt;



            //        rsViewer.LocalReport.DataSources.Clear();
            //        rsViewer.LocalReport.DataSources.Add(rds);
            //        rsViewer.LocalReport.Refresh();

            //    }


            //}
            //catch (Exception ex)
            //{
            //    Response.Write(ex.Message);
            //}
            //finally
            //{

            //}
        }
    }
}